package com.atldy.commerce.config;

import com.zaxxer.hikari.HikariDataSource;
import io.seata.rm.datasource.DataSourceProxy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * <h2> seata 代理始建于配置 </h2>
 *
 * @Author: li-dong-yang
 * @CreateTime: 2021-11-06 11:38
 */
@Configuration
public class DataSourceProxyAutoConfig {

    @Autowired
    private DataSourceProperties dataSourceProperties;

    @Bean("dataSource")
    public DataSource dataSource() {
        HikariDataSource dataSource = new HikariDataSource();
        dataSource.setJdbcUrl(dataSourceProperties.getUrl());
        dataSource.setUsername(dataSourceProperties.getUsername());
        dataSource.setPassword(dataSourceProperties.getPassword());
        return new DataSourceProxy(dataSource);
    }

}